package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.teaching.bo.CheckAnswerResultBo;
import com.ruoyi.teaching.bo.DailyTaskInterviewBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.DailyTasks;
import com.ruoyi.teaching.service.IDailyTasksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 每日任务Controller
 *
 * @author ruoyi
 * @date 2024-04-12
 */
@RestController
@RequestMapping("/daily_tasks")
public class DailyTasksController extends BaseController
{
    @Autowired
    private IDailyTasksService dailyTasksService;

    @GetMapping(value = "/interview/check_answer")
    public AjaxResult checkAnswer(@RequestParam("question") String question,  @RequestParam("answer") String answer){
        return AjaxResult.success(dailyTasksService.checkAnswer(question, answer));
    }

    @GetMapping(value = "/list/interview")
    public List<DailyTaskInterviewBo> queryInterviewList(@RequestParam("date") String date, @RequestParam("interviewType") int interviewType, @RequestParam("classesId") int classesId){
       return dailyTasksService.queryInterviewList(date, interviewType, classesId);
    }

    @PostMapping(value = "/create")
    public void create(){
         dailyTasksService.createDailyTasks();
    }

    @PutMapping(value = "/auto_check")
    public void autoCheck(){
        dailyTasksService.autoCheckDailyTasks();
    }
    /**
     * 查询每日任务列表
     */
    @RequiresPermissions("teaching:daily_tasks:list")
    @GetMapping("/list")
    public TableDataInfo list(DailyTasks dailyTasks)
    {
        startPage();
        List<DailyTasks> list = dailyTasksService.selectDailyTasksList(dailyTasks);
        return getDataTable(list);
    }

    /**
     * 导出每日任务列表
     */
    @RequiresPermissions("teaching:daily_tasks:export")
    @Log(title = "每日任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DailyTasks dailyTasks)
    {
        List<DailyTasks> list = dailyTasksService.selectDailyTasksList(dailyTasks);
        ExcelUtil<DailyTasks> util = new ExcelUtil<DailyTasks>(DailyTasks.class);
        util.exportExcel(response, list, "每日任务数据");
    }

    /**
     * 获取每日任务详细信息
     */
    @RequiresPermissions("teaching:daily_tasks:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dailyTasksService.selectDailyTasksById(id));
    }

    /**
     * 新增每日任务
     */
    @RequiresPermissions("teaching:daily_tasks:add")
    @Log(title = "每日任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DailyTasks dailyTasks)
    {
        return toAjax(dailyTasksService.insertDailyTasks(dailyTasks));
    }

    /**
     * 修改每日任务
     */
    @RequiresPermissions("teaching:daily_tasks:edit")
    @Log(title = "每日任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DailyTasks dailyTasks)
    {
        return toAjax(dailyTasksService.updateDailyTasks(dailyTasks));
    }

    /**
     * 删除每日任务
     */
    @RequiresPermissions("teaching:daily_tasks:remove")
    @Log(title = "每日任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dailyTasksService.deleteDailyTasksByIds(ids));
    }
}
